# _*_ coding : utf-8 _*_
# @Time : 2023/8/27 15:36
# @Author : 寻梦
# @File : 02_selenium元素定位
# @Project : code

'''
鼠标点击模拟
'''
import time

from selenium import webdriver
# 获取浏览器驱动路径
path='driver/chromedriver/chromedriver.exe'

# 需要请求的连接
url="https://www.baidu.com/"

# 创建浏览器对象
brower=webdriver.Chrome(path)

# 执行访问

brower.get(url)

# 获取响应内容

content= brower.page_source

# print(content)

# 获取输入框
input_element= brower.find_element_by_xpath('//input[@id="kw"]')
input_element.send_keys("周杰伦")
# 睡眠2s
time.sleep(2)
# 获取点击按钮
search_button=brower.find_element_by_xpath('//input[@id="su"]')
search_button.click()

# 获取下一页按钮


for t in range(10):
    time.sleep(2)
    # 每一秒后滑动，直到底部
    for j in range(10):
        time.sleep(1)
        js_bottom = "document.documentElement.scrollTop="+str(j*150)
        brower.execute_script(js_bottom)
    time.sleep(1)
    next_as = brower.find_elements_by_xpath('//a[@class="n"]')
    next_as[len(next_as)-1].click()